package com.csdj.config;

import com.csdj.job.MyFirstJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class QuartzConfig {

    /**
     * 调用 定时任务
     * @return
     */
    @Bean  //sping.xml <bean id="" class />
    public JobDetail jobDetail1(){
        return JobBuilder.newJob(MyFirstJob.class).storeDurably().build();
    }

    /**
     * 触发器1 每隔1秒 永久执行
     * @return
     */
    @Bean
    public Trigger trigger1(){
        SimpleScheduleBuilder scheduleBuilder =
                SimpleScheduleBuilder.simpleSchedule()
                        //每一秒执行一次
                        .withIntervalInSeconds(1)
                        //永久重复，一直执行下去
                        .repeatForever();
        return TriggerBuilder.newTrigger()
                .withIdentity("trigger1","group1")
                .withSchedule(scheduleBuilder)
                .forJob(jobDetail1())
                .build();
    }
    // 每两秒触发一次任务
    @Bean
    public Trigger trigger2(){
        return TriggerBuilder.newTrigger()
                .withIdentity("trigger2", "group1")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ? *"))
                        .forJob(jobDetail1())
                        .build();
    }
}
